﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using MaxLeaf.Platform.Commons;

namespace MaxLeaf.Platform.DataContract
{
    /// <summary>
    /// 查询返回内容
    /// </summary>
    [Serializable]
    [DataContract]
    [KnownType(typeof(List<object>))]
    public class SelectResult
    {
        /// <summary>
        /// 返回数据
        /// </summary>
        [DataMember]
        public List<object> Data
        {
            get;
            set;
        }

        /// <summary>
        /// 返回总记录
        /// </summary>
        [DataMember]
        public int TotalCount
        {
            get;
            set;
        }


        /// <summary>
        /// 返回总页数 
        /// </summary>
        [DataMember]
        public int TotalPageCount
        {
            get;
            set;
        }
    }

    /// <summary>
    /// Sum返回内容
    /// </summary>
    [Serializable]
    [DataContract]
    [KnownType(typeof(List<double>))]
    public class SumResult
    {
        /// <summary>
        /// 返回数据
        /// </summary>
        [DataMember]
        public List<double> Data
        {
            get;
            set;
        }

    }

    /// <summary>
    /// 查询时的附加信息
    /// </summary>
    [Serializable]
    [DataContract]    
    [KnownType(typeof(List<Cond>))]
    [KnownType(typeof(List<SortBy>))]
    //[KnownType(typeof(List<LazySubTable>))]
    [KnownType(typeof(List<FieldFilter>))]
    [KnownType(typeof(PageInfo))]
    [KnownType(typeof(List<SumInfo>))]
    public class AddInfo
    {
        /// <summary>
        /// 附加信息类型
        /// </summary>
        [DataMember]
        public AddInfoType Name
        {
            get;
            set;
        }

        /// <summary>
        /// 类型对应List集合
        /// </summary>
        [DataMember]
        public object Value
        {
            get;
            set;
        }
         
    }

    
    /// <summary>
    /// 查询条件
    /// </summary>
    [Serializable]
    [DataContract]
    public class Cond
    {
        /// <summary>
        /// 属性名
        /// </summary>
        [DataMember]
        public string PropName
        {
            get;
            set;
        }

        /// <summary>
        /// 值
        /// </summary>
        [DataMember]
        public object Value
        {
            get;
            set;
        }

        /// <summary>
        /// 比较方式
        /// </summary>
        [DataMember]
        public CompareType Compare
        {
            get;
            set;
        }
    }


    /// <summary>
    /// sum信息,仅限Sum函数使用
    /// </summary>
    [Serializable]
    [DataContract]
    public class SumInfo
    {
        /// <summary>
        /// 要sum的属性名
        /// </summary>
        [DataMember]
        public string PropName
        {
            get;
            set;
        }


        /// <summary>
        /// Sum方式
        /// </summary>
        [DataMember]
        public SumInfoType SumType
        {
            get;
            set;
        }
    }
    /// <summary>
    /// 排序设置
    /// </summary>
    [Serializable]
    [DataContract]
    public class SortBy
    {
        /// <summary>
        /// 需要排序属性
        /// </summary>
        [DataMember]
        public string PropName
        {
            get;
            set;
        }

         
        /// <summary>
        /// 是否倒序
        /// </summary>
        [DataMember]
        public bool  DESC
        {
            get;
            set;
        }
    }

    ///// <summary>
    ///// 需要取数据的关联表信息
    ///// </summary>
    //[Serializable]
    //[DataContract]
    //public class LazySubTable
    //{
    //    /// <summary>
    //    /// 属性名，都以Sub_开头
    //    /// </summary>
    //    [DataMember]
    //    public string PropName
    //    {
    //        get;
    //        set;
    //    }
    //}


    /// <summary>
    /// 显示部分字段
    /// </summary>
    [Serializable]
    [DataContract]
    public class FieldFilter
    {
        /// <summary>
        /// 属性名
        /// </summary>
        [DataMember]
        public string PropName
        {
            get;
            set;
        }
    }

    /// <summary>
    /// 分页，这个不传List,因为只可能有一个
    /// </summary>
    [Serializable]
    [DataContract]
    public class PageInfo
    {
        /// <summary>
        /// 每页输出的记录数
        /// </summary>
        [DataMember]
        public int PageSize
        {
            get;
            set;
        }

        /// <summary>
        /// 当前页数
        /// </summary>
        [DataMember]
        public int PageIndex
        {
            get;
            set;
        }

        /// <summary>
        /// 总记录数
        /// </summary>
        public int TotalCount
        {
            get;
            set;
        }


        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPageCount
        {
            get;
            set;
        }
    }

    public enum AddInfoType
    {
        /// <summary>
        /// 查询条件
        /// </summary>
        Cond = 0
        ,
       /// <summary>
       /// 排序
       /// </summary>
        SortBy
        //,
        ///// <summary>
        ///// 加载关联表,默认不取这些表数据，加快速度
        ///// </summary>
        //LazySubTable   
        ,
        /// <summary>
        /// 只读取部分字段
        /// </summary>
        FieldFilter
        ,
        /// <summary>
        /// 分页信息
        /// </summary>
        PageInfo

         ,
        /// <summary>
        /// Sumb信息
        /// </summary>
        SumInfo

    }

    /// <summary>
    /// 比较方式
    /// </summary>
    public enum CompareType
    {
        /// <summary>
        /// 等于
        /// </summary>
        Equal = 0
        ,
        /// <summary>
        /// 不等于
        /// </summary>
        NotEqual
            ,
        /// <summary>
        /// 大于
        /// </summary>
        Greater
            ,
        /// <summary>
        /// 大于等于
        /// </summary>
        GreaterEqual
            ,
        /// <summary>
        /// 小于
        /// </summary>
        Less
            ,
        /// <summary>
        /// 小于等于
        /// </summary>
        LessEqual
            ,
        /// <summary>
        ///Like查找，%替代一个或多个字符，_仅替代一个字符
        /// </summary>
        Like
            ,
        /// <summary>
        ///Like查找，%替代一个或多个字符，_仅替代一个字符
        /// </summary>
        NotLike
    }


    /// <summary>
    /// sum方式
    /// </summary>
    public enum SumInfoType
    {
        /// <summary>
        /// 求和
        /// </summary>
        Sum = 0
        ,
        /// <summary>
        /// 记数
        /// </summary>
        CountDistinct
            
    }
}
